﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Microsoft.Practices.Unity;

namespace MiniStock.Infrastructure.Implementation
{
    public class DummyRepository<T>: IRepository<T>
    {
        private List<T> InternalList = new List<T>();
        private IQueryable<T> InternalQueryable;
            
        [InjectionConstructor]
        public DummyRepository()
        {
            InternalQueryable = InternalList.AsQueryable();
        }

        public bool BatchCommit
        {
            get { return false; }
            set
            {
            }
        }

        public T Add(T item)
        {
            InternalList.Add(item);
            return item;
        }

        public T Update(T item)
        {
            return item;
        }

        public void Delete(T item)
        {
            InternalList.Remove(item);
        }

        public void Commit()
        {
        }

        public IEnumerator<T> GetEnumerator()
        {
            return InternalQueryable.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return InternalQueryable.GetEnumerator();
        }

        public Type ElementType
        {
            get { return InternalQueryable.ElementType; }
        }

        public System.Linq.Expressions.Expression Expression
        {
            get { return InternalQueryable.Expression; }
        }

        public IQueryProvider Provider
        {
            get { return InternalQueryable.Provider; }
        }

        public void Dispose()
        {
        }
    }
}
